package online.afeibaili.storebackendframework.mapper;

import online.afeibaili.storebackendframework.model.Product;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ProductMapper {
    //插入
    @Insert("insert into product(create_time,name, price, images, description, detail, category, status, remark, sales) values(#{createTime},#{name}, #{price}, #{images}, #{description}, #{detail}, #{category}, #{status}, #{remark}, #{sales})")
    int insert(Product product);
    //删除
    @Delete("delete from product where create_time = (#{createTime})")
    int delete(long createTime);
    //count
    @Select("select count(*) from product")
    int count();
    @Select("select * from product where create_time = (#{createTime})")
    @Result(property = "createTime", column = "create_time")
    Product selectByCreateTime(long createTime);
    //增加sales
    @Update("update product set sales = sales + 1 where create_time = (#{createTime})")
    int updateSales(long createTime);
    //管理员更新销量
    @Update("update product set sales = #{sales} where create_time = (#{createTime})")
    int updateSalesAdmin(long createTime, int sales);
    //更新图片
    @Update("update product set images = #{images} where create_time = (#{createTime})")
    void updateImage(String images, long createTime);
    //更新视频
    @Update("update product set video = #{video} where create_time = (#{createTime})")
    void updateVideo(String video, long createTime);
    //分页展示
    @Select("select images,price,name,create_time from product limit #{start}, #{pageSize}")
    @Result(property = "createTime", column = "create_time")
    List<Map<String, Object>> selectPage(int start,int pageSize);
    //查询价格
    @Select("select price,name from product where create_time = (#{createTime})")
    Map<String, Object> selectPrice(long createTime);
    //查询图片
    @Select("select images from product where create_time = (#{createTime})")
    String selectImageByCreateTime(long createTime);
    //查询视频
    @Select("select video from product where create_time = (#{createTime})")
    String selectVideoByCreateTime(long createTime);

    // 批量查询价格和名称
    List<Product> selectPricesByCreateTimes(@Param("createTimes") List<Long> createTimes);
}